﻿<template>
  <a-card :bordered="false">
    <div class="table-operator">
      <a-button type="primary" icon="plus" @click="hanldleAdd()" v-if="hasPerm('servicebank.Add')">新建</a-button>
      <a-button
      v-if="hasPerm('servicebank.Delete')"
        type="primary"
        icon="minus"
        @click="handleDelete(selectedRowKeys)"
        :disabled="!hasSelected()"
        :loading="loading"
      >删除</a-button>
      <a-button type="primary" icon="redo" @click="getDataList()">刷新</a-button>
    </div>

    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="10">
          <a-col :md="4" :sm="24">
            <a-form-item label="查询类别">
              <a-select allowClear v-model="queryParam.condition">
                <a-select-option key="yqdm">通道商户号</a-select-option>
                <a-select-option key="AcctNo">AcctNo</a-select-option>
                <a-select-option key="CorpId">CorpId</a-select-option>
                <a-select-option key="BankNode">BankNode</a-select-option>
                <a-select-option key="BusiType">BusiType</a-select-option>
                <a-select-option key="ServiceProviderId">ServiceProviderId</a-select-option>
                <a-select-option key="Remark">Remark</a-select-option>
                <a-select-option key="BankName">BankName</a-select-option>
                <a-select-option key="gateway">gateway</a-select-option>
                <a-select-option key="merchantPriKey">merchantPriKey</a-select-option>
                <a-select-option key="easyPayPubKey">easyPayPubKey</a-select-option>
                <a-select-option key="trxCd">trxCd</a-select-option>
                <a-select-option key="merchantMD5Key">merchantMD5Key</a-select-option>
                <a-select-option key="notifyUrl">notifyUrl</a-select-option>
                <a-select-option key="wallet_id">wallet_id</a-select-option>
                <a-select-option key="asset_id">asset_id</a-select-option>
                <a-select-option key="pay_password">pay_password</a-select-option>
                <a-select-option key="gomepayapp_code">gomepayapp_code</a-select-option>
                <a-select-option key="gomepayapp_version">gomepayapp_version</a-select-option>
                <a-select-option key="gomepayplat_form">gomepayplat_form</a-select-option>
                <a-select-option key="gomepayservice_code">gomepayservice_code</a-select-option>
                <a-select-option key="gomepayversion">gomepayversion</a-select-option>
                <a-select-option key="gomepayVerifyKey">gomepayVerifyKey</a-select-option>
                <a-select-option key="CashOutNotifyUrl">CashOutNotifyUrl</a-select-option>
                <a-select-option key="BankId">BankId</a-select-option>
                <a-select-option key="upayPrivateKeyFileName">upayPrivateKeyFileName</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="24">
            <a-form-item>
              <a-input v-model="queryParam.keyword" placeholder="关键字" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-button type="primary" @click="() => {this.pagination.current = 1; this.getDataList()}">查询</a-button>
            <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <a-table
      ref="table"
      :columns="columns"
      :rowKey="row => row.Id"
      :dataSource="data"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      :bordered="false"
      size="middle"
    >
      <span slot="action" slot-scope="text, record">
        <template>
          <a @click="handleEdit(record.Id)" v-if="hasPerm('servicebank.Edit')">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗？"
          v-if="hasPerm('servicebank.Delete')"
    ok-text="确定"
    cancel-text="取消"
    @confirm="handleDelete([record.Id])"
    @cancel="cancel"
  >
    <a href="#">删除</a>
  </a-popconfirm>
        </template>
      </span>
    </a-table>

    <edit-form ref="editForm" :parentObj="this"></edit-form>
  </a-card>
</template>

<script>
import EditForm from './EditForm'

const columns = [
  { title: '通道商户号', dataIndex: 'yqdm', width: '10%' },
  { title: 'AcctNo', dataIndex: 'AcctNo', width: '10%' },
  { title: 'CorpId', dataIndex: 'CorpId', width: '10%' },
  { title: 'BankNode', dataIndex: 'BankNode', width: '10%' },
  { title: 'BusiType', dataIndex: 'BusiType', width: '10%' },
  { title: 'ServiceProviderId', dataIndex: 'ServiceProviderId', width: '10%' },
  { title: 'Remark', dataIndex: 'Remark', width: '10%' },
  { title: 'BankName', dataIndex: 'BankName', width: '10%' },
  { title: 'gateway', dataIndex: 'gateway', width: '10%' },
  { title: 'merchantPriKey', dataIndex: 'merchantPriKey', width: '10%' },
  { title: 'easyPayPubKey', dataIndex: 'easyPayPubKey', width: '10%' },
  { title: 'trxCd', dataIndex: 'trxCd', width: '10%' },
  { title: 'merchantMD5Key', dataIndex: 'merchantMD5Key', width: '10%' },
  { title: 'status', dataIndex: 'status', width: '10%' },
  { title: 'repayFee', dataIndex: 'repayFee', width: '10%' },
  { title: 'notifyUrl', dataIndex: 'notifyUrl', width: '10%' },
  { title: 'wallet_id', dataIndex: 'wallet_id', width: '10%' },
  { title: 'asset_id', dataIndex: 'asset_id', width: '10%' },
  { title: 'pay_password', dataIndex: 'pay_password', width: '10%' },
  { title: 'gomepayapp_code', dataIndex: 'gomepayapp_code', width: '10%' },
  { title: 'gomepayapp_version', dataIndex: 'gomepayapp_version', width: '10%' },
  { title: 'gomepayplat_form', dataIndex: 'gomepayplat_form', width: '10%' },
  { title: 'gomepayservice_code', dataIndex: 'gomepayservice_code', width: '10%' },
  { title: 'gomepayversion', dataIndex: 'gomepayversion', width: '10%' },
  { title: 'gomepayVerifyKey', dataIndex: 'gomepayVerifyKey', width: '10%' },
  { title: 'CashOutNotifyUrl', dataIndex: 'CashOutNotifyUrl', width: '10%' },
  { title: 'IsCashOut', dataIndex: 'IsCashOut', width: '10%' },
  { title: 'BankId', dataIndex: 'BankId', width: '10%' },
  { title: 'upayPrivateKeyFileName', dataIndex: 'upayPrivateKeyFileName', width: '10%' },
  { title: '操作', dataIndex: 'action', scopedSlots: { customRender: 'action' } }
]

export default {
  components: {
    EditForm
  },
  mounted() {
    this.getDataList()
  },
  data() {
    return {
      data: [],
      pagination: {
        current: 1,
        pageSize: 10,
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`
      },
      filters: {},
      sorter: { field: 'Id', order: 'asc' },
      loading: false,
      columns,
      queryParam: {},
      selectedRowKeys: []
    }
  },
  methods: {
    handleTableChange(pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }
      this.sorter = { ...sorter }
      this.getDataList()
    },
    getDataList() {
      this.selectedRowKeys = []

      this.loading = true
      this.$http
        .post('/Base_leasesystem_servicebank/leasesystem_servicebank/GetDataList', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order,
          Search: this.queryParam,
          ...this.filters
        })
        .then(resJson => {
          this.loading = false
          this.data = resJson.Data
          const pagination = { ...this.pagination }
          pagination.total = resJson.Total
          this.pagination = pagination
        })
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    hasSelected() {
      return this.selectedRowKeys.length > 0
    },
    hanldleAdd() {
      this.$refs.editForm.openForm()
    },
    handleEdit(id) {
      this.$refs.editForm.openForm(id)
    },
    handleDelete(ids) {
      var thisObj = this
      this.$confirm({
        title: '确认删除吗?',
        onOk() {
          return new Promise((resolve, reject) => {
            thisObj.$http.post('/Base_leasesystem_servicebank/leasesystem_servicebank/DeleteData', ids).then(resJson => {
              resolve()

              if (resJson.Success) {
                thisObj.$message.success('操作成功!')

                thisObj.getDataList()
              } else {
                thisObj.$message.error(resJson.Msg)
              }
            })
          })
        }
      })
    }
  }
}
</script>

<style>
.ant-table-thead > tr > th
{
  font-weight: 600;
  color: #333333;
}
</style>